<script src="{$base_dir}js/Emr_JsProcessor.js" type="text/javascript"></script>
<script>
{literal}
$(document).ready(function() {
	//sortList('mapped_department');
	{/literal}
	var selectedDep = {$selectedDepId};
	var selectedEmr = {$selectedEmrId};	
	var list=[];	
			"{foreach from=$listOfEmr item=curr key=index}"				
				var listMappedEmr = [];
				listMappedEmr['department_id'] = {$curr.department_id};
				listMappedEmr['emr_id'] = {$curr.emr_id};
				listMappedEmr['emr_name'] = "{$curr.emr_name}";								
				list["{$index}"] = listMappedEmr;   						    	
			"{/foreach}" 
	{literal}
	if (selectedEmr > 0) {
			
		var emrSelectionBox = buildEmrListByDepId(list,selectedDep,selectedEmr);		    	
    	$('#mapped_emr').html(emrSelectionBox);		
    	//sortList('mapped_emr');
    	selectedEmr = $('#mapped_emr option:selected').attr('emr_id');
    	    	   	
    	if (selectedEmr != null && selectedEmr > 0) {
    		{/literal}
    		loadEmrAjax(selectedEmr,{$recordId});
    		{literal}        	        	
    	}
	}	
	
		
	$('#mapped_department').change(function(){	
		$('div#encounterPageContent').html('');
    	var depId = $('#mapped_department option:selected').val();
    	var emrSelectionBox = buildEmrListByDepId(list,depId);    	
    	$('#mapped_emr').html(emrSelectionBox);    			
    	//sortList('mapped_emr');
    	var selectedEmr = $('#mapped_emr option:selected').attr('emr_id');    	
    	if (selectedEmr != null && selectedEmr > 0) {
    		{/literal}
    		loadEmrAjax(selectedEmr,{$recordId});
    		{literal}        	        	
    	}
    });	

	$('#mapped_emr').change(function(){	
		$('div#encounterPageContent').html('');
    	var depId = $('#mapped_department option:selected').val();
    	var selectedEmr = $('#mapped_emr option:selected').val();
    	if (selectedEmr != null && selectedEmr > 0) {
    		{/literal}
    		loadEmrAjax(selectedEmr,{$recordId});
    		{literal}        	        	
    	}
    });	
				
});

{/literal}
</script>
<table class='inline'>
	<tr>
		<td class="label">{translate}Department{/translate}</td>
		<td>
			<select name="mapped_department" id="mapped_department"
				style="width: 180px;">	
				{foreach from=$listOfDep item=curr} 
				{if ($curr.id == $selectedDepId)}
					<option value='{$curr.id}' selected="selected">{$curr.name}</option>
				{else}
					<option value='{$curr.id}'>{$curr.name}</option>
				{/if} {/foreach}
			</select>
		</td>
		<td class="label">{translate}EMR{/translate}</td>
		<td>
			<div id='mapped_emr_content'>
				<select name="mapped_emr" id="mapped_emr" style="width: 250px;" >
				</select>
			</div>
		</td>
	</tr>
</table>
